#include "ftppool.hpp"
#include <string>
#include <WinBase.h>

using std::string;
using namespace com_oocl_monitor::system;

FtpPool::FtpPool(const string& host,const string& port,const string& usr,const string& pwd,unsigned int maxCon)
    :_host(host),_port(port),_usr(usr),_pwd(pwd),_maxCon(maxCon)
{
    _ftpEnv=CurlEnv::getInstance();
	_sem=CreateSemaphore(NULL, maxCon, maxCon, NULL);
}
FtpPool::~FtpPool()
{
	CloseHandle(_sem);
}

Connection *FtpPool::getConnection()
{
    Connection *con=nullptr;
    WaitForSingleObject(_sem,INFINITE);
    con=curl_easy_init();
    return con;
}

void FtpPool::releaseConnection(Connection *con)
{
    curl_easy_cleanup(con);
	ReleaseSemaphore(_sem, 1, NULL);
}
